﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class apps_testHttpPost : System.Web.UI.Page
{
    string chunha ="";
    string nguoithue = "";
    string amends = "";
    string landlord = "";
    string tenantopt = "";
    string diachi="";
    string lanthumay = "";
    string bosung = "";
    string ngayky="";
    string ngaythue;
    string amend1 = "";
    string amend2 = "";
    string amend3 = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Text.StringBuilder displayValues=new System.Text.StringBuilder();
        System.Collections.Specialized.NameValueCollection
            postedValues = Request.Form;
        String nextKey;
        for (int i = 0; i < postedValues.AllKeys.Length; i++)
        {
            nextKey = postedValues.Keys[i];
            if (nextKey.Substring(0, 2) != "__")
            {
                //displayValues.Append("<br>");
               // displayValues.Append(nextKey);
               // displayValues.Append(" = ");
                displayValues.Append(postedValues[i]);
                displayValues.Append("|");
               // displayValues += "<br>" + nextKey + "=" + postedValues[i] + ",";
            }
        }
        //Label1.Text = displayValues.ToString();
        string str = displayValues.ToString();
        string[] chuoitach = str.Split('|');
        //string chuoiketqua = "";
        //foreach (string s in chuoitach)
        //{
        //    if (s.Trim() != "")
        //        chuoiketqua += s;
        //}

        chunha = chuoitach[3];
        nguoithue = chuoitach[5];
        ngaythue = chuoitach[6];
        diachi = chuoitach[7];
        lanthumay = chuoitach[8];
        amends = chuoitach[9];
        amend1 = chuoitach[10];
        amend2 = chuoitach[11];
        amend3 = chuoitach[12];
        bosung = chuoitach[13];
        ngayky = chuoitach[14];


        if (lanthumay != null && lanthumay.Trim() != "")
        {
            lanthu_.InnerText = lanthumay.ToString();
        }
        else
        {
            lanthu_.InnerText = "__________________";
        }
        if (ngayky != null && ngayky.Trim() != "")
        {
            ngayviet_.InnerText = ngayky.ToString();
        }
        else
        {
            ngayviet_.InnerText = "__________________";
        }
        if (bosung != null && bosung.Trim() != "")
        {
            bosung_.InnerHtml = "<b><u>Additional Term</u></b><br/>" + bosung.ToString() + "<br>";
        }
        else
        {
            bosung_.InnerText = "___________________________";
        }
        if (ngaythue != null && ngaythue != "")
        {
            ngaythue_.InnerText = lbNgayki.Text = ngaythue.ToString();
        }
        else
        {
            ngaythue_.InnerHtml = "____day of _______, 20__";
        }
        if (diachi != null && diachi != "")
        {
            diachi_.InnerText = lbDiaChi.Text = diachi.ToString();
        }
        else
        {
            diachi_.InnerHtml = "____________";
        }

        if (amends != null && amends != "")
        {
            //if (amend1.Trim() == "")
            //{
            //    diekhoan_.InnerHtml = "<li>_________________________ <br><br></li>";
            //}
            //else
            {
                if (int.Parse(amends) == 1)
                {
                    diekhoan_.InnerHtml = amend1.ToString() + " <br></li>";
                }
                if (int.Parse(amends) == 2)
                {
                    diekhoan_.InnerHtml = amend1.ToString() + " <br></li>";
                    diekhoan_.InnerHtml += "<li>" + amend2.ToString() + " <br>";
                }
                if (int.Parse(amends) == 3)
                {
                    diekhoan_.InnerHtml = amend1.ToString() + " <br></li>";
                    diekhoan_.InnerHtml += "<li>" + amend2.ToString() + " <br></li>";
                    diekhoan_.InnerHtml += "<li>" + amend3.ToString();
                }
            }
            //if (amend1.Trim() == "")
            //{
            //    
            //}
        }

        lbnguoithue2.Text = nguoithue.ToString();
        lbNguoiThue.Text = nguoithue.ToString();
        lbChunha.Text = chunha.ToString();
        lblchunha2.Text = chunha.ToString();

        //if (Session["paid"] !=null)
        //{
        //    MultiView1.SetActiveView(View1);
        //}
        //else if (Session["paid"] == null)
        //{
        //    MultiView1.SetActiveView(View2);
        //}
        MultiView1.SetActiveView(View1);
        
    }

    protected void GenerateMsWordDoc(object sender, EventArgs e)
    {
        string strBody = "<html>" +
            "<body>" + 
                "<div>Your name is: <b></b></div>" +
                "<table width=\"100%\" style=\"background-color:#cfcfcf;\"><tr><td>1st Cell body data</td><td>2nd cell body data</td></tr></table>" +
                "Ms Word document generated successfully." +
            "</body>" +
            "</html>";
        string fileName = "MsWordSample.doc";
        // You can add whatever you want to add as the HTML and it will be generated as Ms Word docs
        Response.AppendHeader("Content-Type", "application/msword");
        Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
        Response.Write(strBody);
    }
}
